import { ApiProperty } from '@nestjs/swagger';
import {
  IsNotEmpty,
  IsString,
  IsOptional,
  IsNumber,
  IsBoolean,
} from 'class-validator';

// 创建分享链接DTO
export class CreateShareLinkDto {
  @ApiProperty({
    description: '分享类型',
    example: 'APP',
    enum: ['APP', 'SHORT', 'CHAPTER'],
  })
  @IsString()
  @IsNotEmpty()
  shareType: string;

  @ApiProperty({
    description: '目标ID（短剧ID或章节ID）',
    example: 1,
    required: false,
  })
  @IsOptional()
  @IsNumber()
  targetId?: number;

  @ApiProperty({
    description: '过期时间（天数）',
    example: 30,
    required: false,
  })
  @IsOptional()
  @IsNumber()
  expireDays?: number;
}

// 分享链接响应DTO
export class ShareLinkResponseDto {
  @ApiProperty({ description: '分享链接ID' })
  id: number;

  @ApiProperty({ description: '分享token' })
  shareToken: string;

  @ApiProperty({ description: '分享链接' })
  shareUrl: string;

  @ApiProperty({ description: '分享类型' })
  shareType: string;

  @ApiProperty({ description: '目标ID', required: false })
  targetId?: number;

  @ApiProperty({ description: '是否激活' })
  isActive: boolean;

  @ApiProperty({ description: '过期时间', required: false })
  expiresAt?: Date;

  @ApiProperty({ description: '创建时间' })
  createdAt: Date;
}

// 点击分享链接DTO
export class ClickShareLinkDto {
  @ApiProperty({
    description: '分享token',
    example: 'share_abc123',
  })
  @IsString()
  @IsNotEmpty()
  shareToken: string;

  @ApiProperty({
    description: 'IP地址',
    example: '192.168.1.100',
    required: false,
  })
  @IsOptional()
  @IsString()
  ipAddress?: string;

  @ApiProperty({
    description: '用户代理',
    example: 'Mozilla/5.0...',
    required: false,
  })
  @IsOptional()
  @IsString()
  userAgent?: string;
}

// 点击分享链接响应DTO
export class ClickShareLinkResponseDto {
  @ApiProperty({ description: '是否成功' })
  success: boolean;

  @ApiProperty({ description: '消息' })
  message: string;

  @ApiProperty({ description: '是否是新用户' })
  isNewUser: boolean;

  @ApiProperty({ description: '分享者奖励积分' })
  sharerRewardPoints: number;

  @ApiProperty({ description: '点击者奖励积分' })
  clickerRewardPoints: number;

  @ApiProperty({ description: '分享链接信息', required: false })
  shareLink?: {
    id: number;
    shareType: string;
    targetId?: number;
    sharer: {
      id: number;
      nickname: string;
    };
  };
}

// 分享统计响应DTO
export class ShareStatsResponseDto {
  @ApiProperty({ description: '总分享次数' })
  totalShares: number;

  @ApiProperty({ description: '总点击次数' })
  totalClicks: number;

  @ApiProperty({ description: '新用户数量' })
  newUsersCount: number;

  @ApiProperty({ description: '总奖励积分' })
  totalRewardPoints: number;

  @ApiProperty({ description: '今日分享次数' })
  todayShares: number;

  @ApiProperty({ description: '今日点击次数' })
  todayClicks: number;

  @ApiProperty({ description: '今日奖励积分' })
  todayRewardPoints: number;
}

// 分享历史响应DTO
export class ShareHistoryResponseDto {
  @ApiProperty({ description: '分享链接列表' })
  shareLinks: {
    id: number;
    shareToken: string;
    shareType: string;
    targetId?: number;
    clickCount: number;
    rewardPoints: number;
    isActive: boolean;
    expiresAt?: Date;
    createdAt: Date;
  }[];

  @ApiProperty({ description: '总数' })
  total: number;

  @ApiProperty({ description: '当前页' })
  page: number;

  @ApiProperty({ description: '每页数量' })
  pageSize: number;
}
